﻿using System.Xml.Linq;
using Microsoft.EntityFrameworkCore;

namespace MeterReader.WebApi.Models
{
    public class MyDbContext : DbContext
    {
        public DbSet<NewTMeterList> NewTMeterList { get; set; }
        public DbSet<NewTMeter> NewTMeters { get; set; }

        public MyDbContext(DbContextOptions<MyDbContext> options)
            : base(options) { }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<NewTMeterList>(e => e.HasKey(e => e.NameId));
            modelBuilder.Entity<NewTMeter>(e =>
            {
                e.HasKey(e => e.NewTMeterID);
                e.HasOne(d => d.NewTMeterList)
                .WithMany(p => p.NewTMeters)
                .HasForeignKey(p => p.NameId);
            });
        }
    }
}
